import { Navigate, useLocation } from 'react-router-dom';

import { ROUTE_MAP } from '@/application/constants/routerMap';
import Storage from '@/application/utils/storage';

import { RouterInterceptorsProps } from '.';

export function AuthInterceptor({ children, route }: RouterInterceptorsProps) {
  const user = Storage.login.get();
  if (route.auth && !user?.token) {
    console.error('token 过期，请重新登录!');
    return <Navigate to={ROUTE_MAP.HOME} />;
  }

  return children;
}
